package a66weding.com.jiehuntong.application;

import android.app.Application;
import android.content.Context;
import android.graphics.Bitmap;
import android.support.multidex.MultiDex;

import com.android.volley.RequestQueue;
import com.android.volley.toolbox.Volley;
import com.baidu.mapapi.SDKInitializer;
import com.tencent.smtt.sdk.QbSdk;
import com.tencent.smtt.sdk.TbsDownloader;
import com.tencent.smtt.sdk.TbsListener;
import com.umeng.analytics.MobclickAgent;

import org.xutils.x;

import a66weding.com.jiehuntong.common.MyActivityManager;
import a66weding.com.jiehuntong.common.MyMeActivityManager;
import a66weding.com.jiehuntong.common.api.Url;
import a66weding.com.jiehuntong.common.utils.CUtils;
import a66weding.com.jiehuntong.common.utils.CacheUtils;
import a66weding.com.jiehuntong.common.utils.LogUtil;
import a66weding.com.jiehuntong.common.utils.SharesUtils;
import a66weding.com.jiehuntong.common.utils.Tools;

/**
 * Created by y on 2016/5/17.
 */
public class GlobalApplication extends Application{
    public MyActivityManager mActivityManager;
    public MyMeActivityManager mMeActivityManager;  // 这个是我的里面手机号设置的管理类
    public boolean isLogin;
    public boolean isDownNewVersion;
    public RequestQueue getmRequestQueue() {
        return mRequestQueue;
    }
    public void setmRequestQueue(RequestQueue mRequestQueue) {
        this.mRequestQueue = mRequestQueue;
    }
    //创建一个share工具类;
    public SharesUtils share;
    public RequestQueue mRequestQueue;
//    private CrashHandler mCrashHandler;
    public Bitmap bitmap;

    @Override
    public void onCreate() {
        super.onCreate();
        /*FreelineCore.init(this);
        if (LeakCanary.isInAnalyzerProcess(this)) {
            // This process is dedicated to LeakCanary for heap analysis.
            // You should not init your app in this process.
            return;
        }
        LeakCanary.install(this);*/
        // Normal app init code...
        CUtils.init(this);
        x.Ext.init(this);
        x.Ext.setDebug(Url.logToggle);
        Tools.setContext(getApplicationContext());
        /**
         * 百度地图的注册;
         */
        SDKInitializer.initialize(this);
        initX5WebView();
        MobclickAgent.setDebugMode(Url.logToggle);
    }
    /**
     * 加载腾讯X5
     */
    private void initX5WebView() {
        // 搜集本地tbs内核信息并上报服务器，服务器返回结果决定使用哪个内核。
        TbsDownloader.needDownload(getApplicationContext(), false);
        QbSdk.PreInitCallback cb = new QbSdk.PreInitCallback() {

            @Override
            public void onViewInitFinished(boolean arg0) {
                LogUtil.i("initX5WebView", " onViewInitFinished is " + arg0);
            }

            @Override
            public void onCoreInitFinished() {
                LogUtil.i("initX5WebView", " onCoreInitFinished  ");
            }
        };
        QbSdk.setTbsListener(new TbsListener() {
            @Override
            public void onDownloadFinish(int i) {
                LogUtil.i("initX5WebView", "onDownloadFinish");
            }

            @Override
            public void onInstallFinish(int i) {
                LogUtil.i("initX5WebView", "onInstallFinish");
            }

            @Override
            public void onDownloadProgress(int i) {
                LogUtil.i("initX5WebView", "onDownloadProgress:" + i);
            }
        });
        QbSdk.initX5Environment(getApplicationContext(), cb);
    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this) ;
    }

    public RequestQueue getRequestQueueFirst(Context context){
        if(mRequestQueue==null) {
            mRequestQueue = Volley.newRequestQueue(context);
        }
        return mRequestQueue;
    }

    public MyActivityManager getActivityManager(){
        if(mActivityManager==null) {
            mActivityManager=new MyActivityManager();
        }
        return mActivityManager;
    }

    public MyMeActivityManager getMeActivityManager(){      //这个我的手机号的地址管理类的获取对象的方法
        if(mMeActivityManager==null) {
            mMeActivityManager=new MyMeActivityManager();
        }
        return mMeActivityManager;
    }

    public MyMeActivityManager getMainActivityManager(){      //这个我的手机号的地址管理类的获取对象的方法
        if(mMeActivityManager==null) {
            mMeActivityManager=new MyMeActivityManager();
        }
        return mMeActivityManager;
    }

    public MyMeActivityManager getHomeProductdetailActivityManager(){      //这个是店铺详情界面管理类的获取对象的方法
        if(mMeActivityManager==null) {
            mMeActivityManager=new MyMeActivityManager();
        }
        return mMeActivityManager;
    }

    public boolean isLogin() {
        isLogin = CacheUtils.getBooleanFromCache(this,CacheUtils.islogin);
        return isLogin;
    }

    public void setLogin(boolean login) {
        isLogin = login;
    }

    public boolean isDownNewVersion() {
        return isDownNewVersion;
    }

    public void setDownNewVersion(boolean downNewVersion) {
        isDownNewVersion = downNewVersion;
    }

}
